package com.ilancuo.java8;

import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;

public class ConsumerTest {

    public static void main(String[] args) {
//        testConsumer();
//        testFunction();
        testOptional();
    }

    private static void testConsumer() {
        Consumer c = System.out::println;
        c.accept("Hello, world");
        c.accept("hello ilancuo");
        c.accept("bilibili cheers");

        c.andThen(c).andThen(c).accept("Hello, world"); // 多重处理，打印三次Hello, world
    }

    private static void testFunction() {
        Function<Integer, Integer> f1 = i -> i + i;
        Function<Integer, Integer> f2 = i -> i * i;
        Consumer c = System.out::println;
        c.accept(f1.andThen(f2).apply(2));
    }

    private static void testOptional() {
        Integer integer = Optional.ofNullable(null)
                .map(Object::toString)
                .map(String::hashCode)
                .orElse(null);
        System.out.println(integer);
    }
}
